screenshotRef
Captures a rendered view as a UIImage. Attach screenshotRef to any view, then call
screenshot() on the ref to snapshot that view (including its subviews) on demand.
screenshotRef?: RefObject<ScreenshotMaker>
Create the ref with useRef and pass it to the view you want to capture. Once the view has
rendered, ref.current is set to a ScreenshotMaker.
screenshot()returns aUIImage, ornullwhen the view has not been laid out / is off screen.- Call it inside an action (e.g. a button tap), not during rendering — the view must exist first.
Example
Capture a card and save it to the photo library:
Data, Photos and UIImage are globals; no import is needed. Import the UI components, hooks, Script and the ScreenshotMaker type from "scripting".
Notes
screenshotRefworks on any view. The captured image covers the view and all of its subviews.- The ref is filled after the view renders; reading it before the first render returns
null. - To encode the result, use
Data.fromPNG(image)/Data.fromJPEG(image, quality), then save withPhotos.savePhotoor write it to a file withFileManager. - Display a captured image directly with
<Image image={...} />.
